<?php

if (!defined('IN_XLP')) {
    exit('Access Denied!');
}

/**
 * Description of feedbackAction
 * 用户反馈
 * @author xlp
 */
class feedbackAction extends commonAction {

    private $topicScreen = array('意见反馈', '补充小区');

    function __construct() {
        parent::__construct();
        parent::_checkLogin();
        $this->status = array(0 => '<span class="red">未处理</span>', 1 => '已处理', '<span class="red">无效</span>');
    }

    function index() {
        $p = $this->_getid('p', 1);
        $uid = $this->_getid('uid', 0);
        $adminId = $this->_getid('admin_id', 0);
        $status = $this->_getid('status', 0);
        $fmod = $this->_getid('fmod', 0);
        $where = array();
        if ($uid) {
            $where = array('uid' => $uid);
        }
        if ($adminId) {
            $where = array('admin_id' => $adminId);
        }
        if ($fmod) {
            $where = array('stype' => ($fmod - 1));
        }
        if ($status) {
            $where = array('status' => ($status - 1));
        }

        $rs = M('user_feedback')->where($where)->page($p)->order('id DESC')->findAll();
        $total = M('user_feedback')->getTotal();
        if ($rs) {
            foreach ($rs as $k => $v) {
                $rs[$k]['mod_name'] = $this->topicScreen[$v['stype']];
                $rs[$k]['user_name'] = getUser($v['uid']);
                $rs[$k]['admin_name'] = $v['admin_id'] ? parent::_getAdminName($v['admin_id']) : '';
            }
        }
        $this->assign(array('rs' => $rs, 'total' => $total, 'p' => $p, 'status' => $this->status, 'topicScreen' => $this->topicScreen));
//        print_r($this->getAllVar());
        $this->display();
    }

    function detail() {
        $id = $this->_getid('id');
        if (!$id) {
            showError('参数丢失');
        }
        $rs = M('user_feedback')->where(array('id' => $id))->find();
        if (!$rs) {
            showError('主题不存在或者已被删除');
        }
        $rs['content'] = express($rs['content']);
        $rs['lbs_info'] = json_decode($rs['lbs_info'], true);
        $rs['pics_list'] = $rs['photo_counts'] ? D('album')->getPhotosById($rs['uid'], $rs['pics_list']) : array();
//        z($rs);
        $this->assign(array('rs' => $rs));
        $this->display();
    }

    function setting() {
        $id = $this->_postid('id');
        if (!$id) {
            showError('参数丢失');
        }
        $rs = M('user_feedback')->where(array('id' => $id))->find();
        if (!$rs) {
            showError('记录不存在');
        }
        $objData = array(
            'admin_id' => admin::$adminInfo['id'],
            'recontent' => $this->_post('recontent'),
            'status' => $this->_postid('status', 0),
            'retime' => TIME
        );
        M('user_feedback')->update($objData, array('id' => $id));
        $this->JsonReturn('ok', null, 1);
    }

    function delete() {
        $id = $this->_postid('id');
        if (!$id) {
            showError('参数丢失');
        }
        $rs = M('user_feedback')->where(array('id' => $id))->find();
        if (!$rs) {
            showError('记录不存在');
        }
        M('user_feedback')->delete(array('id' => $id));
        $this->JsonReturn('ok', null, 1);
    }

}
